import { call, put } from 'redux-saga/effects';
import { findUser, gerUserDetail, getUserInfo } from '../services/users';

export default {
  namespace: 'users',
  state: {
    userList: {},
  },
  effects: {
    *findUser({ payload }) {
      const response = yield call(findUser, payload);
      yield put({
        type: 'users/getUserList',
        payload: response,
      });
    },
    *gerUserDetail({ payload }) {
      const response = yield call(gerUserDetail, payload);
      yield put({
        type: 'users/getRoles',
        payload: response,
      });
    },
    *getUserInfo({ payload }) {
      const response = yield call(getUserInfo, payload);
      yield put({
        type: 'users/getRoles',
        payload: response,
      });
    },
  },
  reducers: {
    getUserList(state, action) {
      return {
        ...state,
        userList: action.payload,
      };
    },
  },
};
